;
; Copyright 2010 - 2011, The PLDesktop Development Team
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation; either
; version 2.1 of the License, or (at your option) any later version.
;
; This library is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; You should have received a copy of the GNU Lesser General Public
; License along with this library; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

global setjmp:function
global longjmp:function

setjmp:
    push    ebp
    mov     ebp, esp
    push    edi
    mov     edi, [ebp + 8]
    mov     [edi + 0], eax
    mov     [edi + 4], ebx
    mov     [edi + 8], ecx
    mov     [edi + 12], edx
    mov     [edi + 16], esi
    mov     eax, [ebp - 4]
    mov     [edi + 20], eax
    mov     eax, [ebp + 0]
    mov     [edi + 24], eax
    mov     eax, esp
    add     eax, 12
    mov     [edi + 28], eax
    mov     eax, [ebp + 4]
    mov     [edi + 32], eax
    pop     edi
    mov     eax, 0
    leave
    ret

longjmp:
    push    ebp
    mov     ebp, esp
    mov     edi, [ebp + 8]  ; get jmp_buf 
    mov     eax, [ebp + 12] ; store retval in j->eax
    mov     [edi + 0], eax
    mov     ebp, [edi + 24]
    mov     esp, [edi + 28]
    push    dword [edi + 32]
    mov     eax, [edi + 0]
    mov     ebx, [edi + 4]
    mov     ecx, [edi + 8]
    mov     edx, [edi + 12]
    mov     esi, [edi + 16]
    mov     edi, [edi + 20]
    ret
